﻿#ifndef DISPATCHWIDGET_H
#define DISPATCHWIDGET_H

#include <QMap>
#include <QWidget>

class QAbstractButton;
class QGridLayout;
class QPushButton;
class VideoWindow;

class DispatchWidget : public QWidget
{
    Q_OBJECT
public:
    explicit DispatchWidget(QWidget *parent = nullptr);
    ~DispatchWidget();
    void handle_im_msg(int type, qint64 user_id, const QVariantHash &msg);
    void handle_remote_video(qint64 user_id, const QPixmap &pix);
    void handle_audio_volume(qint64 user_id, int volume);

    bool eventFilter(QObject *watched, QEvent *event);
signals:
    void drop(QByteArray encoded, QObject *watched);
    void showContact();
private slots:
    void slot_video_button_clicked();
    void close_video(qint64 uid);
    void drop_received(QByteArray encoded, QObject *watched);
private:
    void setGrid(int row, int column);
    void addP2P(const QMap<int, QVariant> &v, QAbstractButton *button);
    void closeVideo(qint64 user_id, const QString &tooltipFormat);
    void showTooltip(const QString &text, QWidget *childWidget);
    QPushButton* newButton();
    QGridLayout* grid;
    QMap<qint64, QWidget*> videoMap;
    qint64 isTalkingTo;
};

#endif // DISPATCHWIDGET_H
